package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.StringTokenizer;

/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1046 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1046.class.getResource("P1046.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		Color[] table = new Color[16];
		for (int i = 0; i < table.length; i ++) { 
			table[i] = new Color(stdin.readLine());
		}
		
		StringBuffer sb = new StringBuffer("");
		String line = stdin.readLine();
		while (!"-1 -1 -1".equals(line)) {
			Color color = new Color(line);
			line = stdin.readLine();
			int[] ds = new int[table.length];
			for (int i = 0; i < ds.length; i ++) {
				ds[i] = table[i].distance(color);
			}
			int min = Integer.MAX_VALUE;
			int index = 0;
			for (int i = 0; i < ds.length; i ++) {
				if (ds[i] < min) {
					min = ds[i];
					index = i;
				}
			}
			sb.append(color).append(" maps to ")
				.append(table[index]).append("\n");
		}
		System.out.println(sb);
	}
	
	private static class Color {
		
		private int R;
		private int G;
		private int B;
		
		public Color(String str) {
			
			StringTokenizer st = new StringTokenizer(str);
			this.R = Integer.valueOf(st.nextToken());
			this.G = Integer.valueOf(st.nextToken());
			this.B = Integer.valueOf(st.nextToken());
		}
		
		public int distance(Color color) {
			int r = this.R-color.R;
			int g = this.G-color.G;
			int b = this.B-color.B;
			return r*r + g*g + b*b;
		}
		
		public String toString() {
			return "(" + R + "," + G + "," + B + ")";
		}
	}
}
